<?php
if( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 权限分组
 * @author Toby.Tu 2016-04-19
 */
class Permismodule_model extends My_Model{
    public $tab = 'permis_module';
    # code
    /**
     * 新增多条数据
     * @author Toby.tu 2016-08-31
     */
    public function newManyData($param=array(),$tab=''){
        if(empty($tab)) $tab = $this->tab;
        if(empty($param) || empty($tab)) return false;
        $this->db->insert_batch($tab, $param);
    }
    /**
     * 获取权限组对应的权限模块
     * @author Toby.tu 2016-08-31
     */
    public function getPermisModuleByGroupId($permis_id=0){
        if(empty($permis_id)){
            return array();
        }
        $field = 'id,permis_id,name,status';
        $query = $this->db->select($field)->where('permis_id',$permis_id)
                    ->order_by('id')->get($this->tab);
        if(!empty($query)){
            $rows = $query->result_array();
            $permis_list = array();
            foreach ($rows as $row) {
                $permis_list[$row['name']] = $row;
            }
            return $permis_list;
        }
        return array();
    }
    /**
     * 删除权限组下面所有的权限
     * @author Toby.tu 2016-08-31
     */
    public function deletePermisByGroupId($permis_id=0){
        if(empty($permis_id)){
            return array();
        }
        $this->db->delete($this->tab,array('permis_id'=>$permis_id));
    }
}
